/*
 * @Author       : NaN 353362604@qq.com
 * @Date         : 2023-07-14 09:25:27
 * @LastEditTime : 2023-08-11 14:38:01
 * @LastEditors  : NaN 353362604@qq.com
 * @FilePath     : \AdminStration\src\Pages\Front\Assets\Modal\index.jsx
 * @Description  :
 */
import './Modal.scss'
import axios from 'axios'
import { Modal } from 'antd'
import { useBoolean } from 'ahooks'
import { useEffect, useState } from 'react'
import { TableList } from './TableList'
import { TableTest } from './TableTest'
import {
    FrontTAPDetails,
    BeamSliceDetail,
    BeamPedestalDetail,
    CommandTrajectory,
    APIAnnexModal,
    CameraModal,
    InspectionDetails,
    RiskDetailsBox,
    ImageBox,
    SecurityActivityDetailBox,
    AiDetailsModal,
    PersonDetailsModal,
    JTGJThrDataFou,
    NewSciencesModalList,
} from './DivBox'
import { AIBox001 } from './AIBox'
import { ScienceInfoDetailsTwo } from './ScienceInfoDetailsTwo'
import { IPBroadcastModal } from './IPBroadcast'

import { VideoA01 } from './Video'
import { AnnexA01, AnnexA02 } from './Annex'
import { API_LIST } from '../../../../Common/Api/Api'
import { CommonSmallTitle } from '../Common/SmallTitle'
import { Annex, OpenExcel } from '../../../../Common/Modal/ModalList/AnnexList'
import { ProjectDetail } from './ProjectDetail'

const ModalType = {
    TableList,
    TableTest,
    FrontTAPDetails,
    BeamSliceDetail,
    BeamPedestalDetail,
    CommandTrajectory,
    APIAnnexModal,
    AIBox001,
    CameraModal,
    InspectionDetails,
    RiskDetailsBox,
    ImageBox,
    SecurityActivityDetailBox,
    AiDetailsModal,
    PersonDetailsModal,
    JTGJThrDataFou,
    Annex,
    AnnexA01,
    AnnexA02,
    VideoA01,
    IPBroadcastModal,
    ScienceInfoDetailsTwo,
    NewSciencesModalList,
    OpenExcel,
    ProjectDetail,
}

export const FrontModalBox = ({ OptionsCall, OptionsEvent }) => {
    const [Open, { setTrue, setFalse }] = useBoolean(false)
    const [Type, setType] = useState()
    const [Data, setData] = useState()

    useEffect(() => {
        if (OptionsCall) {
            const { type, data } = OptionsCall
            if (type === 'CloseModal') {
                setFalse()
            } else {
                setType(type)
                setData(data)
                setTrue()
            }
        }
    }, [OptionsCall, setFalse, setTrue])

    return (
        <Modal
            className="FrontModalBox"
            open={Open}
            footer={null}
            maskClosable={false}
            onCancel={setFalse}
            destroyOnClose
            width={Data?.width || '80vw'}
            centered
        >
            <CommonSmallTitle title={Data?.title || '操作弹窗'}>
                {(() => {
                    if (!Type) return false
                    const Template = ModalType[Type]
                    return <Template data={Data} OptionsEvent={OptionsEvent} Off={setFalse} />
                })()}
            </CommonSmallTitle>
        </Modal>
    )
}

export const GetAttData = async (uuid, type = 0) => {
    const urlList = uuid => {
        return {
            0: `${API_LIST()['getConstructionInfoManageDetail']}?InfoManageUuid=${uuid}`,
            1: `${API_LIST()['getFormDetail']}?formUuid=${uuid}`,
            2: `${API_LIST()['getSecurityTrainAttachment']}?securityTrainUuid=${uuid}`,
            3: `${API_LIST()['getAttachmentDetails']}?annexUuid=${uuid}`,
        }
    }

    const { data } = await axios.get(urlList(uuid)[type])
    const { list } = data
    const { length } = list
    if (length === 0) return false
    else if (length === 1)
        return {
            type: 'Annex',
            data: { url: list[0].fileUrl || list[0].attachment.fileUrl, title: list[0].tableName, width: '90vw' },
        }
    else return { type: 'AnnexMore', data: { title: '附件列表', data: { list } } }
}
